﻿using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.Globalization;
using System.Web.Mvc;
using System.Web.Security;
using Expenses.DAL.Repositories;
using Expenses.Domain.Entities;

namespace Expenses.Models
{

    public class InvoiceModel
    {
        public  Guid Id { get; set; }
        public  Expense Expense { get; set; }
        public Guid ExpenseId { get; set; }
        public ICollection<Expense> Expenses { get; set; }

        [Required]
        [DataType(DataType.Currency)]
        [Display(Name = "Amount")]
        public  float Amount { get; set; }

        [Required]
        [DataType(DataType.Date)]
        [Display(Name = "Billing Date")]
        public  DateTime? BillingDate { get; set; }

        [Required]
        [DataType(DataType.Date)]
        [Display(Name = "Expiration Date")]
        public  DateTime? ExpirationDate { get; set; }

        [DataType(DataType.Date)]
        [Display(Name = "Payment Date")]
        public  DateTime? PaymentDate { get; set; }

        public  bool IsPaid { get; set; }

        public InvoiceModel(){}

        public InvoiceModel(Invoice invoice)
        {
            Amount = invoice.Amount;
            BillingDate = invoice.BillingDate;
            Expense = invoice.Expense;
            ExpirationDate = invoice.ExpirationDate;
            IsPaid = invoice.IsPaid;
            PaymentDate = invoice.PaymentDate;

            var p = new ExpenseRepository();
            Expenses = p.GetAll();
        }

        public Invoice CreateInvoiceFromModel()
        {
            var invoice = new Invoice{  Amount          = this.Amount, 
                                        BillingDate     = this.BillingDate, 
                                        Expense         = this.Expense,
                                        ExpirationDate  = this.ExpirationDate,
                                        IsPaid          = this.IsPaid,
                                        PaymentDate     = this.PaymentDate  };

            return invoice;
        }
    }
}